﻿using System;
using System.IO;

namespace Utility
{
    public class LogHelper
    {
        private static readonly LogHelper Instance = new LogHelper();

        public static LogHelper GetLogHelper()
        {
            return Instance;
        }

        #region 写日志

        public void WriteLog(string strMsg)
        {
            //1.创建第一个大的文件夹  名字叫：ORA_LNG
            string firstFoler = "ErrorLog";
            string secondFoler = DateTime.Now.ToString("yyyy-MM-dd");
            if (!Directory.Exists("D:" + "\\" + firstFoler))
            {
                //创建该文件夹
                Directory.CreateDirectory("D:" + "\\" + firstFoler);
                //创建二级文件夹
                Directory.CreateDirectory("D:" + "\\" + firstFoler + "\\" + secondFoler);
            }
            else
            {
                //2.创建第二级文件夹  以当天的日期命名
                if (!Directory.Exists("D:" + "\\" + firstFoler + "\\" + secondFoler))
                {
                    //创建
                    Directory.CreateDirectory("D:" + "\\" + firstFoler + "\\" + secondFoler);
                }
            }

            string url = "D:" + "\\" + firstFoler + "\\" + secondFoler;

            string filename = url + "\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt ";

            File.AppendAllText(filename, strMsg + ";\r\n===================================================\r\n");
        }

        #endregion 写日志
    }
}